package com.wandian.login.mvvm.userregist;

import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.text.InputType;
import android.util.Log;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.mylib.libcore.adapter.BasePagerAdapter;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.databinding.BindToolBarBinding;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.ToastUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.login.R;
import com.wandian.login.databinding.LgActivityRegistBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 注册
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_REGIST)
public class RegistActivity extends  BaseMVVMActivity<RegistActivityViewModel>  {
    private LgActivityRegistBinding dataBinding;
    private BindToolBarBinding bindToolBarBinding;
    private List<String> titleList=new ArrayList<>();
    private List<Fragment> fragments = new ArrayList<>();
    private BasePagerAdapter myAdapter;
    private RelativeLayout rl_back;
    private TextView tv_title;
    private  boolean openEyes = false;
    public boolean userAgreementState = true;

    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.lg_activity_regist);
        dataBinding.setLifecycleOwner(this);
        dataBinding.bindToolBar.toolBarTvTitle.setText("注册");
        dataBinding.setViewModel(mViewModel);
        initClink();
    }
    private void initClink(){
        dataBinding.bindToolBar.toolBarIvBack.setOnClickListener(v -> {
            finishhideSoftBoard();
            finish();
        });

        dataBinding.ivYzm.setOnClickListener(v -> {
            userAgreementState = !userAgreementState;
            Log.d("userAgreementState",userAgreementState+"");
            if(userAgreementState){
                dataBinding.ivYzm.setImageResource(R.drawable.img_item_choosed);
            }else {
                dataBinding.ivYzm.setImageResource(R.drawable.img_item_unchoose);
            }
        });

        dataBinding.ivLoginEye.setOnClickListener(v -> {
            finishhideSoftBoard();
            openEyes = !openEyes;
            if(openEyes){
                dataBinding.ivLoginEye.setImageResource(R.drawable.login_eye_open);
                dataBinding.etPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
            }else {
                dataBinding.ivLoginEye.setImageResource(R.drawable.login_eye_close);
                dataBinding.etPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            }
        });


        dataBinding.tvRegister.setOnClickListener(v -> {
            finishhideSoftBoard();
            if(UIUtils.isEmpty(dataBinding.etPhone.getText()) || dataBinding.etPhone.getText().toString().length()!= 11){
                ToastUtil.show("请输入手机号码");
                return;
            }

            if(UIUtils.isEmpty(dataBinding.etYzm.getText()) || dataBinding.etYzm.getText().toString().length()!= 6){
                ToastUtil.show("请输入手机验证码");
                return;
            }
            if(UIUtils.isEmpty(dataBinding.etPassword.getText()) || dataBinding.etPassword.getText().toString().length()< 6){
                ToastUtil.show("请输入6-20位密码");
                return;
            }
            if(userAgreementState){
                ToastUtil.show("已注册");
                finishhideSoftBoard();
                finish();
              //  mViewModel.regist(dataBinding.etPhone.getText().toString(),dataBinding.etYzm.getText().toString(),dataBinding.etPassword.getText().toString());
            }else {
                ToastUtil.show("请勾选用户协议");
                return;
            }
        });

    }


}
